/**
 * @describe 判断用户状态
 * @param { Object } (userInfo) 用户信息
**/
export function checkUser (userInfo) {
	let off, action,
		sdkUserInfo = window.localStorage.getItem('SDK_USER_INFO'), // 设备SDK用户信息缓存
		sign = userInfo.sign, // 1已激活2未激活3审核中
		ytskStatus = userInfo.ytskStatus; // 1 游客2商户3推广商户4运营中心5战略合作（行牛,嘉信5G）

	if (sdkUserInfo) sdkUserInfo = JSON.parse(sdkUserInfo);

	if (ytskStatus == 1) { // 未购买设备
		off = 1;
		action = function () {
			Jsborya.pageJump({
				url: '',
				depiction: '加盟',
				stepCode: '2009',
				destroyed: true,
			});
		}
	} else if (sign == 2) { // 未激活
		off = 2;
		action = function () {
			Jsborya.dialog({
				content: "",
				btn: [],
				code: '649'
			});
		}
	} else if (sdkUserInfo && sdkUserInfo.merchantInfo.sign == 2) { // 未激活
		off = 2;
		Jsborya.pageJump({
			url: '../merchantActive/device.html',
			depiction: '加盟',
			stepCode: '999',
			destroyed: true,
		});
	} else if (sign == 3) { // 激活审核中
		off = 3;
		action = function () { };
	} else {//已激活
		off = 4;
		action = function () { };
	}
	return {
		off,
		action
	}
}
/**
 * @describe 获取用户状态
 * @param { Object } (vm) vue实例
**/
export function getUserInfoFromServer (vm) {
	let json = {
		userInfo: vm.userInfo,
		params: {}
	};

	return new Promise((resolve) => {
		vm.AJAX('/ums/c/user/userInfo', json, function (res) {
			if (res) {
				let user = res.data;

				vm.setStore('SDK_USER_INFO', user);

				resolve(user);
			}
		}, false, true, (errRes) => {
			vm.errorBubble(errRes);
			resolve(false);
		});
	})
}